package com.dianrui.moonfire.adapter;

import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;

import com.dianrui.moonfire.R;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class BlueTeethAdapter extends BaseAdapter {

    private List<BluetoothDevice> mBluelist;
    Context context;
    public BlueTeethClickListener blueTeethClickListener;

    public BlueTeethAdapter(List<BluetoothDevice> mBluelist, Context context) {
        this.mBluelist = mBluelist;
        this.context = context;
    }


    @Override
    public int getCount() {
        return mBluelist.size();
    }

    @Override
    public Object getItem(int position) {
        return mBluelist.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }
    public interface BlueTeethClickListener {
        void userCar(String msg_id);

    }

    public void setBlueTeethClickListener(BlueTeethClickListener blueTeethClickListener) {
        this.blueTeethClickListener=blueTeethClickListener;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
          ViewHolder holder;
        if (convertView != null) {
            holder = (ViewHolder) convertView.getTag();
        } else {
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_blueteeth_list, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }
        BluetoothDevice blueDevice = mBluelist.get(position);
        final String deviceName = blueDevice.getName();
        if (null != deviceName && deviceName.length() > 0) {
            holder.deviceName.setText(blueDevice.getName());

        } else {
            holder.deviceName.setText("未知设备");

        }

        holder.startbtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
        return convertView;
    }

     class ViewHolder {
        @BindView(R.id.device_name)
        TextView deviceName;
         @BindView(R.id.start_use_car)
        Button startbtn;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
